package com.sitr.house.controller;


import com.sitr.house.common.model.House;
import com.sitr.house.common.model.User;
import com.sitr.house.common.model.page.PageData;
import com.sitr.house.common.model.page.PageParams;
import com.sitr.house.service.AgencyService;
import com.sitr.house.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class AgencyController {

    @Autowired
    private AgencyService agencyService;

    @Autowired
    private HouseService houseService;

    @RequestMapping("/agency/agentList")
    public String agentList(Integer pageSize, Integer pageNum, ModelMap modelMap) {
        PageData<User> ps = agencyService.getAllagents(PageParams.build(pageSize, pageNum));
        modelMap.put("ps", ps);
        return "/user/agent/agentList";
    }

    @RequestMapping("agency/agentDetail")
    public String agentDetail(Long id, ModelMap modelMap) {
        User user = agencyService.getAgentDetail(id);
        House query = new House();
        query.setUserId(id);
        query.setBookmarked(false);
        PageData<House> bindHouse = houseService.queryHouse(query, new PageParams(3, 1));
        if (bindHouse != null) {
            modelMap.put("bindHouses", bindHouse.getList());

        }
        modelMap.put("agent", user);
        return "/user/agent/agentDetail";
    }
}
